<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>PRODUCT ADJUST / UPDATE</title>

<script type="text/javascript">

    $().ready(function() {
        view();
        calendar.makeCalender("adjustDate");
        
        if($("#roleId").val() == "3"){
            $("#bo_btn").attr("style", "display:none");
        }
        
        $("#onList").bind("click",function(){
            location="/productAdjust.html";            
        });

        /* 저장버튼 */
        $("#saveBtn").bind("click",function(){    
            $("form[name='productAdjustUpdateFrm']").submit();
        });
        
        /* textarea 체크 */
        $("#remark").bind("keyup",function(){
            textAreaKyUp(this);  //조회 직후에도 호출해야해서 function 으로 뺌.. 
        });
        
        /* 메인폼 서브밋 */
        $("form[name='productAdjustUpdateFrm']").ajaxForm({
            dataType: "json",
            beforeSerialize: function($form, options) {
                //return $("form[name='orderFrm']").valid();  jquery 벨류데이션 플러그인 사용시
                 if( !validation() ){       //화면 항목 점검 시작
                    return false;
                }
            },
            success:function(data) {
               if(data.result == true){
            	   if(data.resultDup == 'N'){
                       alert("Duplication");
                   }else{
                       alert("Complete the save");
                       location="/productAdjust.html"; 
                   }   
               }               
           },
           error:function(){alert("ERROR!");}
        });  
    });
    
    /************************************************************************/
    /*                          textarea 글자 수 체크                       */
    /************************************************************************/
    /* textarea 체크 */
    var oldStr;
    function textAreaKyUp(obj){
        var str = obj.value;
        if(str.length <= 1000){
            oldStr = str;
            contents = "("+str.length+" / ";
            $("#cnt").html(contents);
        }else{
            alert("Limited string has been exceeded.");
            $("#pop_remark").val(oldStr);
        }
    };

    /* 조회 펑션 */
    function view(){
        $.post(
                '/getProductAdjustDetailView.json', {
                adjustNo : $("#adjustNo").val()
                },
            function(data) {
                //reSetValidete(); //벨류데이션 초기화
                
                searchDataMaping(data);    //DATA맵핑 
            });
    }

    /* searchData 맵핑 */
    function searchDataMaping(data){
        var val = ""; 
        for(var v in data.resultDetailMap) {       //상단 조회 결과 맵핑 조회return값이 한건임
            $("#"+v).val(data.resultDetailMap[v]);
            if(v == "remark"){
                var contents = "("+data.resultDetailMap[v].length+" / ";
                $("#cnt").html(contents);
            }
        }        
    }

    function validation(){

    	var goodsName       = $("#goodsName").val();
        var mawb            = $("#mawb").val();
        var hawb          = $("#hawb").val();
        var batchNo          = $("#batchNo").val();
        var qty        = $("#qty").val();
        var adjustDate     = $("#adjustDate").val();
        
        if(goodsName==null   || goodsName=="") {   alert("Product Name required!!"); $("#goodsName").focus(); return false; }
        if(mawb==null        || mawb=="") { alert("Mawb required!!"); $("#mawb").focus(); return false; }
        if(hawb==null        || hawb=="") { alert("Hawb required!!"); $("#hawb").focus(); return false; }
        if(batchNo==null     || batchNo=="") { alert("BatchNo required!!"); $("#batchNo").focus(); return false; }
        if(qty==null         || qty=="") { alert("Qty required!!"); $("#qty").focus(); return false; }
        if(adjustDate==null   || adjustDate=="") { alert("AdjustDate required!!"); $("#adjustDate").focus(); return false; }
        
        return true;
    } 
    
</script>
</head>
<body>
<div class="wrap">
    <form name="productAdjustUpdateFrm" method="post" action="/saveProductAdjust.json">
    <div class="pagetitle">
        <h1>PRODUCT ADJUST / UPDATE</h1>
    </div>
    <div>
        <table class="TableST">
            <tr>
                <th>Product</th>
                <td>
                    <input type="text" class="inSTR40" name="goodsName" id="goodsName" readonly/>
                    <input type="hidden" class="inSTR40" name="goodsCode" id="goodsCode"/>
                </td>
            </tr>
            <tr>
                <th>MAWB</th>
                <td><input type="text" class="inSTR40" name="mawb" id="mawb" readonly/></td>
            </tr>
            <tr>
                <th>HAWB</th>
                <td><input type="text" class="inSTR40" name="hawb" id="hawb" readonly/></td>
            </tr>
            <tr>
                <th>Batch No</th>
                <td><input type="text" class="inSTR40" size="80" name="batchNo" id="batchNo" readonly/></td>
            </tr>
            <tr>
                <th>Qty</th>
                <td><input type="text" class="inST40" size="80" name="qty" id="qty" maxlength="7"/></td>
            </tr>
            <tr>
                <th>Adjust Date</th>
                <td>
                    <input type="text" class="inSTR40" size="80" name="adjustDate" id="adjustDate" readonly/>
                </td>
            </tr>
            <tr>
               <th>Remarks<br><span id="cnt">(0 / </span>1000)</th>
               <td colspan="2"><textarea class="teST" wrap="virtual" id="remark" name="remark"></textarea></td>
            </tr>
            
         </table>
    </div>
    <div class="bo_btn" id="bo_btn" style="display: block;">
        <ul class="btnst"><li class="a"><a href="#" id="onList" >LIST</a></li></ul>
        <ul class="btnst"><li class="a"><a href="#" id="saveBtn" >SAVE</a></li></ul>
    </div>
    <input type="hidden" name="adjustNo" id="adjustNo" value="${adjustNo}"/>
    <input type="hidden" name="saveStatus" id="saveStatus" value="UPDATE"/>
    <input type="hidden" name="roleId" id="roleId" value="${requestScope.roleId}">
    </form>
</div>
</body>
</html>